#!/bin/sh
#
# softbench_to_sniff
#
# Convert SoftBench notifications to SNiFF+ requests.
#
# This script registers with SoftBench for FILE-MODIFIED notifications
# and sends a `file_changed' request via the program `sniffaccess' to SNiFF+.
#
# Usage:
#   softbench_to_sniff
#

if [ -z "${child_proc:-}" ]; then
  child_proc=1
  export child_proc

  # restart this program as a child of ciclient
  # with "/bin/sh" if $# = 0, "$@" expands to NULL parameter

  if [ $# = 0 ]; then
    exec ciclient -toolclass SNIFF -mode name -o 5 -e $0
  else
    exec ciclient -toolclass SNIFF -mode name -o 5 -e $0 "$@"
  fi
fi

unset child_proc

PROG=`basename $0`
HOSTNAME=`uname -n`

echo make_reply_trigger -host $HOSTNAME -action FILE-MODIFIED -status PASS >&5
echo make_reply_trigger -action STOP -status PASS >&5

while read COMMAND ARGS
do
  eval $ARGS
  case $COMMAND in
  nvreply_trigger)
    case $action in
    FILE-MODIFIED)
      sniffaccess file_changed '*/' `basename $operand`
      ;;
    STOP)
      if [ $toolclass = MSG-SERVER ]; then
	exit 0
      fi
      ;;
    *)
      echo $PROG: unknown action: $action
      ;;
    esac
    ;;

  *)
    echo $PROG: unknown command: $COMMAND
    ;;
  esac
done

exit 0
